﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Engine.NetClasses
{
   

    public static class Packet
    {
        
        public static T getPacketClientLogin<T>(PacketTypeClient typePacket,byte[] data)
        {
            object tmp = null;
           // PacketTypeloginClient typePacket = (PacketTypeloginClient)data[2];
            switch (typePacket)
            {
                case PacketTypeClient.RequestLoginAuth:
                  
                    tmp = new RequestLoginAuth(data);
                    
                    break;
                default:
                    break;
            }
            if (tmp == null)
            {
                return default(T);
            }
            else
            {
                return (T)tmp;
            }
        }
        public static T getPacketServerLogin<T>(PacketTypeServer typePacket ,byte[] data)
        {
            object tmp = null;
           
            switch (typePacket)
            {
                case PacketTypeServer.Init:
                    tmp = new Init(data);
                    break;
                default:
                    break;
            }
            if (tmp == null)
            {
                return default(T);
            }
            else
            {
                return (T)tmp;
            }
        }
        public static T getPacket<T>(byte[] data) where T:IPacket
        {
            T tmp = default(T);
            tmp.Convert(data);
            return tmp;
            
        }
    }
}
